<?php

define("MYSQL_HOST","localhost");
define("MYSQL_USER","dutyu");
define("MYSQL_PSW","wxy123");

function connectDB(){
    return mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PSW);
}

class ActivityAction extends Action{

    /**
     * orgId: //组织ID
     * orderType : //排序方式（”atv_time”--时间排序，”atv_heat”--活动热度排序）
    */
    public function getActivityList($orgId, $orderType='atv_time'){
        $condition['org_id']=$orgId;
        //$condition['atv_subj']='subj1';
        $atv = D('Activity');
        //$atv = new ActivityModel();
        if($orderType=='atv_time')
        {
            $atvData = $atv->where($condition)->order('atv_start_time desc')->select();
        }
        else
        {
            $atvData = $atv->where($condition)->order('page_view desc')->select();
        }

        //echo $atv->getLastSql();
        //echo dump($atvData);
        $atvNewData = $atv->fieldToOutputContent($atvData);
        //echo dump($atvNewData);

        $this->ajaxReturn(output_json_success($atvNewData));
    }

    public function getActivityById($atvId){
        $condition['id']=$atvId;
        $atv = D('Activity');
        $atvData = $atv->where($condition)->select();
        //echo $atv->getLastSql();
        //echo dump($data);
        $atvNewData = $atv->fieldToOutputContent($atvData);

        $this->ajaxReturn(output_json_success($atvNewData));
    }

    public function modifyActivityById( $atvId, $atvSubj="", $atvName="", $atvStartTime="",
                                       $atvEndTime="", $signUpStartTime="", $signUpEndTime="",$atvDesc="",
                                       $atvType="", $atvCity="", $atvUni="", $atvAddress="",
                                       $posterId="", $upperBound="" )
    {
        $condition['atvId'          ] = $atvId          ;
        $condition['atvSubj'        ] = $atvSubj        ;
        $condition['atvName'        ] = $atvName        ;
        $condition['atvStartTime'   ] = $atvStartTime   ;
        $condition['atvEndTime'     ] = $atvEndTime     ;
        $condition['signUpStartTime'] = $signUpStartTime;
        $condition['signUpEndTime'  ] = $signUpEndTime  ;
        $condition['atvDesc'        ] = $atvDesc        ;
        $condition['atvType'        ] = $atvType        ;
        $condition['atvCity'        ] = $atvCity        ;
        $condition['atvUni'         ] = $atvUni         ;
        //$condition['atvAddress'     ] = $atvAddress     ;
        $condition['posterId'       ] = $posterId       ;
        $condition['upperBound'     ] = $upperBound     ;
        foreach ($condition as $key=>$value)
        {
            if($value==''){
                unset($condition[$key]);
            }
        }

        $atv = D('Activity');
        $atv->create($condition);
        $atv->save();
        //echo $atv->getLastSql();

        $this->ajaxReturn(output_json_success(''));
    }
}

?>